Imports System.Text.RegularExpressions

Public Class frmIndexGenretor

  Private mObjIndexGnrt As New clsDBScriptGnrt
  Private mHstIndex As New Hashtable
  Public mTableId As Integer
  Public mTableName As String = String.Empty

  Private Sub frmScriptGenretor_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim lStrDBStyle As String = String.Empty
    Dim lArrDBStyle As String()

    If mPrRefreshConn() = False Then Exit Sub

    Index.Enabled = False
    dgvIndex.Enabled = False

    cmbType.Items.Add("I")
    cmbType.SelectedIndex = 0

    mFnReadValue("DatabaseStyle", "", "Oracle,SqlCE", lStrDBStyle, Application.StartupPath + "\" + DDL_TEMPLATE_FILE)
    lArrDBStyle = Split(Split(lStrDBStyle, Chr(0))(0), ",")
    For Each lStr As String In lArrDBStyle
      cmbDBType.Items.Add(lStr)
    Next
    cmbDBType.SelectedIndex = 0

    txtTableName.Text = mTableName
    Call cmdReset_Click(New Object, New System.EventArgs)

    If mTableName.Trim <> "" Then
      LoadIndexDtls()
    End If
  End Sub

  Private Sub txtTableName_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtTableName.TextChanged
    LoadIndexDtls()
  End Sub

  Private Sub dgvIndex_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvIndex.CellClick

    If e.RowIndex = -1 Then
      Exit Sub
    End If

    If e.ColumnIndex = 0 Then
      If dgvIndex.Rows(e.RowIndex).Cells("clmIndexType").Value <> "P" And dgvIndex.Rows(e.RowIndex).Cells("clmIndexType").Value <> "F" Then
        If MsgBox("Delete index " & dgvIndex.Rows(e.RowIndex).Cells("clmIndexName").Value & "?", MsgBoxStyle.YesNo, gCONST_MSG_HEADER) = MsgBoxResult.Yes Then
          dgvIndex.Rows.RemoveAt(e.RowIndex)
          dgvIndex.ClearSelection()
        End If
      Else
        MsgBox("Can not delete PK or FK record", MsgBoxStyle.Information, gCONST_MSG_HEADER)
      End If
    Else
      Call dgvIndex_SelectionChanged(sender, New System.EventArgs)
    End If
  End Sub

  Private Sub dgvIndex_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dgvIndex.SelectionChanged
    Dim lStrClms() As String

    If dgvIndex.SelectedRows.Count <> 0 And dgvIndex.RowCount <> 0 Then
      If dgvIndex.CurrentCell.ColumnIndex <> 0 Then
        txtIndexName.Text = dgvIndex.SelectedRows.Item(0).Cells("clmIndexName").Value

        lstSelectColumns.Items.Clear()
        lStrClms = Split(dgvIndex.SelectedRows.Item(0).Cells("clmColumns").Value, " , ")
        For Each lStrValue As String In lStrClms
          lstSelectColumns.Items.Add(lStrValue)
        Next

        If dgvIndex.SelectedRows.Item(0).Cells("clmIndexType").Value = "P" Then
          txtIndexName.Enabled = False
          cmbType.Enabled = False
          lstColumns.Enabled = False
          lstSelectColumns.Enabled = False
          cmdUpdate.Enabled = False
          cmdAdd.Enabled = False
          cmdToRight.Enabled = False
          cmdToLeft.Enabled = False
          If cmbType.Items.Contains("PK") = False Then _
            cmbType.Items.Add("PK")
          cmbType.Text = "PK"
        ElseIf dgvIndex.SelectedRows.Item(0).Cells("clmIndexType").Value = "F" Then
          txtIndexName.Enabled = False
          cmbType.Enabled = False
          lstColumns.Enabled = False
          lstSelectColumns.Enabled = False
          cmdUpdate.Enabled = False
          cmdAdd.Enabled = False
          cmdToRight.Enabled = False
          cmdToLeft.Enabled = False
          If cmbType.Items.Contains("FK") = False Then _
            cmbType.Items.Add("FK")
          cmbType.Text = "FK"
        ElseIf dgvIndex.SelectedRows.Item(0).Cells("clmIndexType").Value = "I" Then
          txtIndexName.Enabled = True
          cmbType.Enabled = True
          lstColumns.Enabled = True
          lstSelectColumns.Enabled = True
          cmdUpdate.Enabled = True
          cmdAdd.Enabled = False
          cmdToRight.Enabled = True
          cmdToLeft.Enabled = True
          If cmbType.Items.Contains("PK") = True Then _
            cmbType.Items.Remove("PK")
          If cmbType.Items.Contains("FK") = True Then _
            cmbType.Items.Remove("FK")
          cmbType.Text = "I"
        End If

      End If
    End If
  End Sub

  Private Sub cmdViewTables_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdViewTables.Click
    FrmDisplayGrid.sCallingPurpose = gENMU_PUEPOSE.Tables
    FrmDisplayGrid.sCallingControl = "txtTableName"
    FrmDisplayGrid.ShowDialog()
  End Sub

  Private Sub cmdReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdReset.Click
    cmdUpdate.Enabled = False
    cmdAdd.Enabled = True
    cmbType.SelectedIndex = 0
    txtIndexName.Clear()
    lstSelectColumns.Items.Clear()
    txtIndexName.Enabled = True
    cmbType.Enabled = True
    lstColumns.Enabled = True
    lstSelectColumns.Enabled = True
    cmdToRight.Enabled = True
    cmdToLeft.Enabled = True
    If cmbType.Items.Contains("PK") = True Then _
      cmbType.Items.Remove("PK")
    If cmbType.Items.Contains("FK") = True Then _
      cmbType.Items.Remove("FK")
    cmbType.Text = "I"
    lstColumns.DataSource = mObjIndexGnrt.PopulateColmuns(txtTableName.Text)
  End Sub

  Private Sub cmdToRight_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdToRight.Click, lstColumns.DoubleClick
    For Each lObject As Object In lstColumns.SelectedItems
      If lstSelectColumns.Items.Contains(lObject) = True Then
        MsgBox("This column " & lObject.ToString & " has been added", MsgBoxStyle.Information, gCONST_MSG_HEADER)
      Else
        lstSelectColumns.Items.Add(lObject)
      End If
    Next
  End Sub

  Private Sub cmdToLeft_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdToLeft.Click, lstSelectColumns.DoubleClick
    Dim lArrClms As New ArrayList
    For Each lObject As Object In lstSelectColumns.SelectedItems
      lArrClms.Add(lObject.ToString)
    Next
    For Each lStr As String In lArrClms
      lstSelectColumns.Items.Remove(lStr)
    Next
  End Sub

  Private Sub cmdAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAdd.Click

    Dim lLngIndexId As Long
    Dim lLngMaxIndexId As Long = 0
    Dim lIntNewRowIndex As Integer
    Dim lStrIndexName As String = String.Empty
    Dim lStrIndexType As String = String.Empty
    Dim lStrSelectedClms As String = String.Empty
    Dim lStrClmsId As String = String.Empty
    Dim lStrClmsSqno As String = String.Empty

    If Len(txtIndexName.Text.Trim) = 0 Then
      MsgBox("Please input index name", MsgBoxStyle.Information, gCONST_MSG_HEADER)
      Exit Sub
    Else
      lStrIndexName = txtIndexName.Text.Trim
    End If

    If lstSelectColumns.Items.Count = 0 Then
      MsgBox("Please select one or more colmuns", MsgBoxStyle.Information, gCONST_MSG_HEADER)
      Exit Sub
    End If

    For Each lObjRow As DataGridViewRow In dgvIndex.Rows
      If txtIndexName.Text.Trim = lObjRow.Cells("clmIndexName").Value.ToString Then
        MsgBox("Record with index name " & lStrIndexName & " has been added", MsgBoxStyle.Information, gCONST_MSG_HEADER)
        Exit Sub
      End If
    Next

    lLngIndexId = mObjIndexGnrt.GetMaxIndexId() + 1
    For Each lObjRow As DataGridViewRow In dgvIndex.Rows
      If lObjRow.Cells("clmIndexId").Value >= lLngMaxIndexId Then
        lLngMaxIndexId = lObjRow.Cells("clmIndexId").Value
      End If
    Next
    If lLngIndexId <= lLngMaxIndexId Then lLngIndexId = lLngMaxIndexId + 1

    For i As Integer = 0 To lstSelectColumns.Items.Count - 1
      If i = 0 Then
        lStrSelectedClms = lstSelectColumns.Items(0).ToString
        lStrClmsId = mObjIndexGnrt.GetColmunId(lstSelectColumns.Items(0).ToString, mTableId)
        lStrClmsSqno = mObjIndexGnrt.GetColmunSqno(lstSelectColumns.Items(0).ToString, mTableId)
      Else
        lStrSelectedClms += " , " & lstSelectColumns.Items(i).ToString
        lStrClmsId += " , " & mObjIndexGnrt.GetColmunId(lstSelectColumns.Items(i).ToString, mTableId)
        lStrClmsSqno += " , " & mObjIndexGnrt.GetColmunSqno(lstSelectColumns.Items(i).ToString, mTableId)
      End If

    Next

    If cmbType.Text = "I" Then lStrIndexType = "I"

    lIntNewRowIndex = dgvIndex.Rows.Add()
    With dgvIndex.Rows(lIntNewRowIndex)
      .Cells("clmIndexId").Value = lLngIndexId
      .Cells("clmIndexName").Value = lStrIndexName
      .Cells("clmColumns").Value = lStrSelectedClms
      .Cells("clmIndexType").Value = lStrIndexType
      .Cells("clmClmId").Value = lStrClmsId
      .Cells("clmClmSqno").Value = lStrClmsSqno
    End With
    dgvIndex.Rows(lIntNewRowIndex).Cells(1).Selected = True
    Call dgvIndex_SelectionChanged(dgvIndex, New System.EventArgs)
  End Sub

  Private Sub cmdUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdUpdate.Click
    Dim lStrIndexName As String = String.Empty
    Dim lStrIndexType As String = String.Empty
    Dim lStrSelectedClms As String = String.Empty
    Dim lStrClmsId As String = String.Empty
    Dim lStrClmsSqno As String = String.Empty

    If Len(txtIndexName.Text.Trim) = 0 Then
      MsgBox("Please input index name", MsgBoxStyle.Information, gCONST_MSG_HEADER)
      Exit Sub
    Else
      lStrIndexName = txtIndexName.Text.Trim
    End If

    If lstSelectColumns.Items.Count = 0 Then
      MsgBox("Please select one or more colmuns", MsgBoxStyle.Information, gCONST_MSG_HEADER)
      Exit Sub
    End If

    For i As Integer = 0 To lstSelectColumns.Items.Count - 1
      If i = 0 Then
        lStrSelectedClms = lstSelectColumns.Items(0).ToString
        lStrClmsId = mObjIndexGnrt.GetColmunId(lstSelectColumns.Items(0).ToString, mTableId)
        lStrClmsSqno = mObjIndexGnrt.GetColmunSqno(lstSelectColumns.Items(0).ToString, mTableId)
      Else
        lStrSelectedClms += " , " & lstSelectColumns.Items(i).ToString
        lStrClmsId += " , " & mObjIndexGnrt.GetColmunId(lstSelectColumns.Items(i).ToString, mTableId)
        lStrClmsSqno += " , " & mObjIndexGnrt.GetColmunSqno(lstSelectColumns.Items(i).ToString, mTableId)
      End If

    Next

    If cmbType.Text = "I" Then lStrIndexType = "I"

    If dgvIndex.SelectedRows.Count <> 0 Then
      With dgvIndex.SelectedRows(0)
        .Cells("clmIndexName").Value = lStrIndexName
        .Cells("clmColumns").Value = lStrSelectedClms
        .Cells("clmIndexType").Value = lStrIndexType
        .Cells("clmClmId").Value = lStrClmsId
        .Cells("clmClmSqno").Value = lStrClmsSqno
      End With
    Else
      Call cmdAdd_Click(New Object, New System.EventArgs)
    End If
  End Sub

  Private Sub cmdCommit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCommit.Click
    Dim lArrUpdateQuery As New ArrayList
    Dim lBlnDelflag As Boolean = False
    Dim lStrQuery As String = String.Empty
    Dim lStrClms() As String
    Dim lStrClmId() As String
    Dim lStrClmSqno() As String

    If Len(txtTableName.Text.Trim) = 0 Then
      MsgBox("Please select one table", MsgBoxStyle.Information, gCONST_MSG_HEADER)
      Exit Sub
    End If

    'for update and insert
    For Each lObjRow As DataGridViewRow In dgvIndex.Rows
      lStrClms = Split(lObjRow.Cells("clmColumns").Value.ToString, " , ")
      lStrClmId = Split(lObjRow.Cells("clmClmId").Value.ToString, " , ")
      lStrClmSqno = Split(lObjRow.Cells("clmClmSqno").Value.ToString, " , ")
      For i As Integer = 0 To lStrClms.Length - 1
        If mHstIndex.ContainsKey(lObjRow.Cells("clmIndexId").Value & "_" & lStrClmId(i)) = True Then
          lStrQuery = "UPDATE TRDX_TABL_INDX SET " & _
                      " TTL_TABL_IDXX=" & mTableId & _
                      ",TTL_INDX_IDXX=" & lObjRow.Cells("clmIndexId").Value.ToString & _
                      ",TTL_INDX_TYPE='" & lObjRow.Cells("clmIndexType").Value.ToString & "'" & _
                      ",TTL_COLM_IDXX=" & lStrClmId(i) & _
                      ",TTL_COLM_SEQC_NMBR=" & lStrClmSqno(i) & _
                      ",TTL_INDX_NAME='" & lObjRow.Cells("clmIndexName").Value.ToString & "'" & _
                      " WHERE TTL_TABL_IDXX=" & mTableId & _
                      " AND TTL_INDX_IDXX=" & lObjRow.Cells("clmIndexId").Value.ToString & _
                      " AND TTL_COLM_IDXX=" & lStrClmId(i)
        Else
          lStrQuery = "INSERT INTO TRDX_TABL_INDX (TTL_TABL_IDXX,TTL_INDX_IDXX,TTL_INDX_TYPE,TTL_COLM_IDXX,TTL_COLM_SEQC_NMBR,TTL_INDX_NAME) VALUES " & _
                      " (" & mTableId & _
                      "," & lObjRow.Cells("clmIndexId").Value.ToString & _
                      ",'" & lObjRow.Cells("clmIndexType").Value.ToString & "'" & _
                      "," & lStrClmId(i) & _
                      "," & lStrClmSqno(i) & _
                      ",'" & lObjRow.Cells("clmIndexName").Value.ToString & "')"
        End If
        lArrUpdateQuery.Add(lStrQuery)
      Next
    Next

    'for delete
    For Each lObjKey As Object In mHstIndex.Keys
      lBlnDelflag = True
      For Each lObjRow As DataGridViewRow In dgvIndex.Rows
        lStrClmId = Split(lObjRow.Cells("clmClmId").Value.ToString, " , ")
        For i As Integer = 0 To lStrClmId.Length - 1
          If lObjKey = lObjRow.Cells("clmIndexId").Value & "_" & lStrClmId(i) Then
            lBlnDelflag = False
            Exit For
          End If
        Next
      Next
      If lBlnDelflag = True Then
        lStrQuery = "DELETE TRDX_TABL_INDX " & _
                    " WHERE TTL_INDX_IDXX=" & Split(lObjKey, "_")(0) & _
                    " AND TTL_COLM_IDXX=" & Split(lObjKey, "_")(1)
        lArrUpdateQuery.Add(lStrQuery)
      End If
    Next

    If mObjIndexGnrt.Update(lArrUpdateQuery) = True Then
      LoadIndexDtls()
      MsgBox("Save successfully", MsgBoxStyle.Information, gCONST_MSG_HEADER)
    Else
      MsgBox("Save failed", MsgBoxStyle.Information, gCONST_MSG_HEADER)
    End If
  End Sub

  Private Sub cmdGenerate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdGenerate.Click
    Dim lArrScript As New ArrayList
    Dim lStrScript As String
    Dim lStrFileName As String = "Index_" + txtTableName.Text.Trim + ".sql"
    Dim lStrScriptTemplate As String
    Dim lArrClms() As String

    lStrScriptTemplate = ReadTemplateScript(cmbDBType.Text.Trim, TM_CREATE_INDEX)
    For Each lObjRow As DataGridViewRow In dgvIndex.Rows
      If lObjRow.Cells("clmIndexType").Value <> "P" And lObjRow.Cells("clmIndexType").Value <> "F" Then
        lStrScript = lStrScriptTemplate
        lStrScript = ReplaceParameter(lStrScript, TM_INDEX_NAME, lObjRow.Cells("clmIndexName").Value.ToString)
        lStrScript = ReplaceParameter(lStrScript, TM_TABLE_NAME, txtTableName.Text.Trim)
        lArrClms = Split(lObjRow.Cells("clmColumns").Value.ToString, " , ")
        For Each lStrClm As String In lArrClms
          lStrScript = ReplaceParameter(lStrScript, TM_START, String.Empty)
          lStrScript = ReplaceParameter(lStrScript, TM_COLUMN_NAME, lStrClm)
        Next
        lStrScript = ReplaceParameter(lStrScript, TM_END, String.Empty)
        lStrScript = ReplaceParameter(lStrScript, TM_REMOVE, String.Empty)
        lArrScript.Add(lStrScript)
      End If
    Next

    lStrScript = String.Empty
    For Each lStr As String In lArrScript
      lStr = ReplaceSepcChar(lStr)
      lStrScript = lStrScript + lStr + vbCrLf
    Next

    If GenerateScript(lStrfileName, lStrScript) = True Then
      MsgBox("Save as '" & lStrfileName & "' successfully", MsgBoxStyle.Information, gCONST_MSG_HEADER)
    Else
      MsgBox("Save failed", MsgBoxStyle.Information, gCONST_MSG_HEADER)
    End If
  End Sub

  Private Sub cmdGenerateAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdGenerateAll.Click
    Dim lArrScript As New ArrayList
    Dim lStrScript As String
    Dim lObjFilePath As String = String.Empty
    Dim lStrFileName As String
    Dim objTags As New clsTags
    Dim lObjDataTable As DataTable
    Dim lObjArrRow() As DataRow
    Dim lStrScriptTemplate As String

    Dim lStrTableName As String = String.Empty
    Dim lStrIndexId As String = String.Empty
    Dim lStrIndexName As String = String.Empty
    Dim lStrClms As String = String.Empty
    Dim lArrClms() As String
    Dim lIntArrIndex As Integer

    Try

      lStrScriptTemplate = ReadTemplateScript(cmbDBType.Text.Trim, TM_CREATE_INDEX)

      If SelectFolder(lObjFilePath) = False Then
        Exit Sub
      End If

      mPrRefreshConn()
      objTags.fnSelectAllTables()
      lObjDataTable = mObjIndexGnrt.PopulateAllIndex()

      While objTags.mDrTags.Read()
        lArrScript.Clear()
        lStrTableName = objTags.mDrTags("TABM_TABLE_NAME").ToString

        lObjArrRow = lObjDataTable.Select("TABM_TABLE_NAME='" & lStrTableName & "'")

        If lObjArrRow.Length <> 0 Then
          For Each lObjRow As DataRow In lObjArrRow

            If lObjRow("TTL_INDX_TYPE") <> "P" And lObjRow("TTL_INDX_TYPE") <> "F" Then
              If lObjRow("TTL_INDX_IDXX").ToString = lStrIndexId Then
                lStrClms += " , " & lObjRow("TAB_COL_NAME")
              Else
                lIntArrIndex = lArrScript.Add(String.Empty)
                lStrIndexId = lObjRow("TTL_INDX_IDXX")
                lStrClms = lObjRow("TAB_COL_NAME")
                lStrIndexName = lObjRow("TTL_INDX_NAME")
              End If

              lStrScript = lStrScriptTemplate
              lStrScript = ReplaceParameter(lStrScript, TM_INDEX_NAME, lStrIndexName)
              lStrScript = ReplaceParameter(lStrScript, TM_TABLE_NAME, lStrTableName)
              lArrClms = Split(lStrClms, " , ")
              For Each lStrClm As String In lArrClms
                lStrScript = ReplaceParameter(lStrScript, TM_START, String.Empty)
                lStrScript = ReplaceParameter(lStrScript, TM_COLUMN_NAME, lStrClm)
              Next
              lStrScript = ReplaceParameter(lStrScript, TM_END, String.Empty)
              lStrScript = ReplaceParameter(lStrScript, TM_REMOVE, String.Empty)
              lArrScript(lIntArrIndex) = lStrScript
            End If

          Next
        End If

        lStrScript = String.Empty
        For Each lStr As String In lArrScript
          lStr = ReplaceSepcChar(lStr)
          lStrScript = lStrScript + lStr + vbCrLf
        Next

        lStrFileName = "Index_" + lStrTableName + ".sql"
        If Len(lStrScript.Trim) <> 0 Then
          WriteFile(lObjFilePath, lStrFileName, lStrScript)
        End If
      End While

      MsgBox("Save in folder - " & lObjFilePath & " successfully", MsgBoxStyle.Information, gCONST_MSG_HEADER)
    Catch ex As Exception
      MsgBox("Save failed", MsgBoxStyle.Information, gCONST_MSG_HEADER)
    End Try

  End Sub

  '----------------------------------------------------------------------------

  Private Sub LoadIndexDtls()

    Dim lObjDataReader As OracleClient.OracleDataReader
    Dim lIntrowIndex As Integer = -1

    If Len(txtTableName.Text.Trim) = 0 Then
      MsgBox("Please select one table", MsgBoxStyle.Information, gCONST_MSG_HEADER)
      Exit Sub
    End If

    mTableId = mObjIndexGnrt.GetTableId(txtTableName.Text.Trim)
    lObjDataReader = mObjIndexGnrt.PopulateIndex(txtTableName.Text.Trim)
    If IsNothing(lObjDataReader) = False Then
      dgvIndex.Rows.Clear()
      mHstIndex.Clear()
      While lObjDataReader.Read
        mHstIndex.Add(lObjDataReader.Item("TTL_INDX_IDXX") & "_" & lObjDataReader.Item("TTL_COLM_IDXX"), lObjDataReader.Item("TTL_INDX_NAME"))
        If lIntrowIndex <> -1 AndAlso lObjDataReader.Item("TTL_INDX_IDXX") = dgvIndex.Rows(lIntrowIndex).Cells("clmIndexId").Value Then
          dgvIndex.Rows(lIntrowIndex).Cells("clmColumns").Value += " , " & lObjDataReader.Item("TAB_COL_NAME")
          dgvIndex.Rows(lIntrowIndex).Cells("clmClmId").Value += " , " & lObjDataReader.Item("TTL_COLM_IDXX").ToString
          dgvIndex.Rows(lIntrowIndex).Cells("clmClmSqno").Value += " , " & lObjDataReader.Item("TTL_COLM_SEQC_NMBR").ToString
        Else
          lIntrowIndex = dgvIndex.Rows.Add()
          With dgvIndex.Rows(lIntrowIndex)
            .Cells("clmIndexId").Value = lObjDataReader.Item("TTL_INDX_IDXX")
            .Cells("clmIndexName").Value = lObjDataReader.Item("TTL_INDX_NAME")
            .Cells("clmColumns").Value = lObjDataReader.Item("TAB_COL_NAME")
            .Cells("clmIndexType").Value = lObjDataReader.Item("TTL_INDX_TYPE")
            .Cells("clmClmId").Value = lObjDataReader.Item("TTL_COLM_IDXX").ToString
            .Cells("clmClmSqno").Value = lObjDataReader.Item("TTL_COLM_SEQC_NMBR").ToString
          End With
        End If
      End While
      dgvIndex.ClearSelection()
    End If

    lstColumns.DataSource = mObjIndexGnrt.PopulateColmuns(txtTableName.Text)

    Index.Enabled = True
    dgvIndex.Enabled = True
    cmdUpdate.Enabled = False
    cmdAdd.Enabled = True

  End Sub

End Class